package cc.geguol.Utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by 13687 on 2017/2/11.
 */
public class JdbcUtils {
	private static String url = "jdbc:mysql://localhost:3306/student";
	private static String user="root";
	private static String pwd = "root";


	/**
	 * @return 获取一个连接
	 */
	public static Connection getConnection() throws SQLException {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			return DriverManager.getConnection(url,user,pwd);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public static void closeAll(Connection con, Statement statement, ResultSet set){
		if (set!=null){
			try {
				set.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (statement!=null){
			try {
				statement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (con!=null){
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
